//
//  BottomView.swift
//  新浪微博项目
//
//  Created by 王炯 on 16/7/23.
//  Copyright © 2016年 王炯. All rights reserved.
//

import UIKit

//第三部分:底部视图(三个按钮)
class BottomView: UIView
{
    
    //懒加载三个button
    //(1)转发
    private lazy var retweetButton:UIButton = {
       
        let button = UIButton()
        
        button.setImage(UIImage.init(named:"timeline_icon_retweet"), forState: .Normal)
        
        // 设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        button.setTitle("转发", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        return button
    }()
    
    //(2)评论
    private lazy var commentButton:UIButton = {
        
        let button = UIButton()
        
        button.setImage(UIImage.init(named:"timeline_icon_comment"), forState: .Normal)
        
        // 设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        button.setTitle("评论", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        return button
    }()
    
    
    //(3)赞
    private lazy var likeButton:UIButton = {
        
        let button = UIButton()
        
        button.setImage(UIImage.init(named:"timeline_icon_unlike"), forState: .Normal)
        
        // 设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        button.setTitle("赞", forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        return button
    }()
    
    
    //懒加载两条竖线
    let  line1:UIImageView = {
       
        let lineView = UIImageView(imgName: "timeline_card_bottom_line")
        
        return lineView
        
    }()
    
    let  line2:UIImageView = {
        
        let lineView = UIImageView(imgName: "timeline_card_bottom_line")
        
        return lineView
        
    }()
    
    
    

    override init(frame: CGRect)
    {
        super.init(frame: frame)
        
        //布局界面
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //布局界面
    func setUpUI()
    {
        self.backgroundColor = UIColor.whiteColor()
        
        //添加三个按钮
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(likeButton)
        //添加两条竖线
        addSubview(line1)
        addSubview(line2)
        
        
        
        //设置3个button的约束
        //(1)转发按钮
        //只设置:左,上,下,与评论按钮宽相等
        retweetButton.snp_makeConstraints { (make) in
            make.leading.top.bottom.equalTo(self)
            make.width.equalTo(self.commentButton)
        }
        
        //(2)评论按钮
        //只设置:上，下,左，与点赞按钮的宽相等
        commentButton.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton.snp_trailing)
            make.width.equalTo(self.likeButton)
        }
        
        //(3)赞按钮
        //只设置:上，下，左，右
        likeButton.snp_makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
        
        //设置竖线的约束
        line1.snp_makeConstraints { (make) in
            make.centerY.equalTo(self.snp_centerY)
            make.centerX.equalTo(retweetButton.snp_trailing)
        }
        
        line2.snp_makeConstraints { (make) in
            make.centerY.equalTo(self.snp_centerY)
            make.centerX.equalTo(commentButton.snp_trailing)
        }
        
        
    }
    
    //从外界获取CellViewModel数据来设置cell的上控件的一些属性
    //此时获取到的viewModel数据是通过CellViewModel类对获取的网络数据dataModel进行数据处理好的数据
    var viewModel:CellViewModel?{
        
     
        didSet
        {
            //转发按钮的文本改变
            self.retweetButton.setTitle(viewModel?.retweetStr, forState: UIControlState.Normal)
            
            //评论按钮的文本改变
            self.commentButton.setTitle(viewModel?.commentStr, forState:UIControlState.Normal)
            
            //点赞按钮的文本改变
            self.likeButton.setTitle(viewModel?.likeStr, forState: UIControlState.Normal)
            
        }
        
    }
    
    
}
